\documentclass{ctexart}

\usepackage{listings}

\lstset{
basicstyle=\ttfamily,
columns=fullflexible,%可以自动换行
linewidth=1\linewidth, %设置代码块与行同宽
breaklines=true,%在单词边界处换行。
showstringspaces=false， %去掉空格时产生的下划的空格标志, 设置为true则出现
breakatwhitespace=ture,%可以在空格处换行
escapechar=`%设置转义字符为反引号
}

\title{code report of chapter one}
\author{谢飞扬\\  信息与计算科学 3210104010}
\date{\today}

\begin{document}
\maketitle
\setlength{\parindent}{0pt}

\section{problem A}
将共同的输入参数放在抽象基类中EquationSolver，并提供了solve和print两个函数接口，其中solve是纯虚函数。
下面是头文件中部分代码，$\sim\sim\sim$为代码省略部分，主要展示了类成员变量设计，接口与实现及测试代码不在报告中给出。

\subsection{头文件部分代码}
\begin{lstlisting}
class EquationSolver
{
public:
    EquationSolver(double (*func)(double arg), int maxinum, double eps)
        : max_iter_num{maxinum}, epsilon{eps}, func_ptr{func}
    {
        iter_num = 0;
        result = 0;
        func_ptr = func;
    }

    virtual double solve() = 0; // pure virtual function
    void print();
    int iter_num;

protected:
    int max_iter_num;
    double epsilon;                 // make |f(result)|<epsilon
    double (*func_ptr)(double arg); // point to function f
    double result;                  // the solution of the equation
};

class BisectionMethod : public EquationSolver
{
public:
    ~~~
    double len;

private:
    double left, right; // left and right bound of the interval
    double delta;       // make right-left<delta
};

class NewtonMethod : public EquationSolver
{
    ~~~
private:
    double x0;                             // initial value of iteration sequence
    double (*derivedfunc_ptr)(double arg); // point to derived function of f
};
class SecantMethod : public EquationSolver
{
    ~~~
private:
    double x0, x1; // initial value and second value of iteration sequence
    double delta;  // make |xn-xn-1|<delta
};
\end{lstlisting}

\section{problem B}
number of iterations: 27\\
numerical solution: 0.860334\\
the function value at the result: 8.03375e-09\\

number of iterations: 26\\
numerical solution: 0.641186\\
the function value at the result: -1.53804e-08\\

number of iterations: 27\\
numerical solution: 1.82938\\
the function value at the result: 9.4115e-09\\

function may not continuous\\

\section{problem C}
number of iterations: 3\\
numerical solution: 4.49341\\
the function value at the result: -3.69482e-12\\

number of iterations: 4\\
numerical solution: 7.72525\\
the function value at the result: -4.51381e-11\\

\section{problem D}
number of iterations: 19\\
numerical solution: 3.14134\\
the function value at the result: -7.95431e-09\\

number of iterations: 10\\
numerical solution: 1.30633\\
the function value at the result: -6.52234e-12\\

number of iterations: 7\\
numerical solution: -0.188685\\
the function value at the result: -6.31696e-09\\

\section{problem E}
number of iterations: 26\\
numerical solution: 0.165019\\
the function value at the result: -4.75217e-08\\

number of iterations: 5\\
numerical solution: 0.165019\\
the function value at the result: 4.99886e-10\\

number of iterations: 5\\
numerical solution: 0.165019\\
the function value at the result: 1.00542e-12\\

\section{problem F}

\subsection{(a)}
number of iterations: 2\\
numerical solution: 32.9722\\
the function value at the result: 9.66338e-13\\

\subsection{(b)}
number of iterations: 2\\
numerical solution: 33.1689\\
the function value at the result: 1.30272e-09\\

\subsection{(c)}
number of iterations: 7\\
numerical solution: 32.9722\\
the function value at the result: -1.06581e-14\\
number of iterations: 38\\
numerical solution: -3.33749e+07\\
the function value at the result: 2.38801e-09\\
原因：上面是两次割线法的输出，第一次的初始值为0，30，第二次的初始值则为0，180。显然题给函数是关于a的周期函数，所以一个初始值离33越远，割线斜率越小，因此经过一次迭代后越容易偏离33的不动点，最后收敛到其他不动点。

\end{document}
